package com.ias.agdis_r.adapter;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.ias.agdis_r.R;

/**
 * 任务进展Adapter
 * @author guoxr
 *
 */
public class TaskProcessAdapter extends BaseAdapter {

	private Context context = null;
	private List<Map<String, Object>> list;

	public TaskProcessAdapter(Context context, List<Map<String, Object>> list) {
		this.context = context;
		this.list = list;
	}

	public final class ViewHolder {
		public TextView tv_title, tv_msg, tv_time;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder = new ViewHolder();
		if (convertView == null) {// 如果加载item布局为null
			LayoutInflater inflater = LayoutInflater.from(context);
			convertView = inflater.inflate(R.layout.item_taskprocess, null);// 设置加载布局
			holder.tv_title = (TextView) convertView
					.findViewById(R.id.tv_title);
			holder.tv_msg = (TextView) convertView.findViewById(R.id.tv_msg);
			holder.tv_time = (TextView) convertView.findViewById(R.id.tv_time);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.tv_title.setText((String) list.get(position).get("title"));
		holder.tv_msg.setText((String) list.get(position).get("msg"));
		holder.tv_time.setText((String) list.get(position).get("time"));
		return convertView;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		if (list != null) {
			return list.size();
		} else {
			return 0;
		}
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
}
